package cn.thread;

public class DeadLock {
    public static void main(String args[]){
        Pesoin p1=new Pesoin(1,"小芳");
        Pesoin p2=new Pesoin(0,"小雪");
      p1.start();
      p2.start();
    }
}
class Pesoin extends Thread {
    int co;
     String name;
    public Pesoin(int co,String name) {
        this.co = co;
        this.name=name;
    }

    static A001 a001 = new A001();
    static A002 a002 = new A002();

    @Override
    public void run() {
        make();
    }
    public void make(){
        if(co==0) {
            synchronized (a001) {
                System.out.println(this.name+"得到a001");
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (a002) {
                System.out.println(this.name+"得到a002");
            }

        }else{

            synchronized (a002) {
                System.out.println(this.name+"得到a002");
            }
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (a002) {
                System.out.println(this.name+"得到a002");
            }
        }


    }

}
class A001{
    String name="A001资源";
}



class A002{
    String name="A002资源";
}